package com.sua.mybatis.impl;

import java.util.Date;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.Test;

import com.sua.mybatis.dao.UserDao;
import com.sua.mybatis.po.UserPO;

public class UserDaoImpl implements UserDao {

	private SqlSessionFactory sqlSessionFactory;

	public UserDaoImpl(SqlSessionFactory sqlSessionFactory) {
		this.sqlSessionFactory = sqlSessionFactory;

	}
	public UserDaoImpl() {
	}

 	public UserPO findUserById(int id) throws Exception {
		SqlSession sqlSession = sqlSessionFactory.openSession();
		UserPO user = sqlSession.selectOne("test.findUserById", 1);
		sqlSession.close();
		return user;
	}

	public void insertUser(UserPO user) throws Exception {
		SqlSession sqlSession = sqlSessionFactory.openSession();
		sqlSession.insert("test.insertUser", user);
		sqlSession.commit();
		sqlSession.close();

	}

	public void deleteUser(int id) throws Exception {
		SqlSession sqlSession = sqlSessionFactory.openSession();
		sqlSession.delete("test.deleteUser", id);
		sqlSession.commit();
		sqlSession.close();

	}

}
